<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>js/jquery专项</title>
		<link rel="stylesheet" href="http://cdn.amazeui.org/amazeui/2.7.2/css/amazeui.min.css" />
		
	</head>
	<body>
		<div class="am-container dataDiv">
			<section class="am-panel am-panel-primary">
			  <header class="am-panel-hd">
			    <h3 class="am-panel-title">考试功能演示</h3>
			  </header>
			  <div class="am-panel-bd">
			  		<form action="index.do">
					<table class="am-table am-table-bordered am-text-center">
						<thead>
							<tr>
								<th colspan="3"> 
									<button title="点击此按钮刷新下方表格数据，ajax处理" class="am-btn am-btn-primary" onclick="shuaxin();">刷新数据</button>
								</th>
							</tr>
							<tr>
								<th><input type="checkbox" id="CheckAll" ></th>
								<th>序号</th>
								<th>姓名</th>
								<th>年龄</th>
							</tr>
							
							
						</thead>
						<tbody>
							
 					<c:forEach items="${results }" var="sp" varStatus="i">
		 				<tr>
		 					<td><input type="checkbox" name="checkid" value="${sp.id }" onclick="countCheck();"> </td>
		 					<td>${i.index+1 }</td>
		 					<td>${sp.name }</td>
		 					<td>${sp.age }岁</td>
		 				</tr>
	 				</c:forEach>
	
							<tr>
								
								<td colspan="3">
									<button class="am-btn am-btn-primary" title="点击后将所有数据的checkbox修改为选中状态" id="check" onclick="javascript:CheckedAll();">全选</button>
									<button class="am-btn am-btn-primary" title="点击后将所有数据的checkbox修改为未选中状态" onclick="javascript:CheckedNo();">全不选</button>
									<button class="am-btn am-btn-primary" title="点击后，已选择的checkbox改为未选择，未选择的checkbox改为已选择" onclick="javascript:CheckedRev();"> 反选</button>
									<button class="am-btn am-btn-warning" title="点击后提交已选择数据的value值" onclick="tijiao();">提交已选择数据</button>
								</td>
							</tr>
						</tbody>
					</table>
					</form>
					<div>
						<p>点击提交按钮后，如果未选择任何数据，在这里打印提示信息，提示用户先选择数据再提交</p>
						<span id="tishi"></span>
						<p>如果已选择数据，则提交并且在后台打印提交的所有数据。然后将当前项目的运行路径获取并且返回，在这里显示了</p>
					</div>
			  </div>
			</section>
		</div>
<script src="static/js/jquery-1.12.4.min.js"></script>
<script src="static/js/jquery-confirm.js"></script>
<script type="text/javascript">
//全选
function CheckedAll(){ 
$(':checkbox').attr('checked','checked'); 
} 
//全不选 
function CheckedNo(){ 
$(':checkbox').attr('checked',''); 
}
//反选 
function CheckedRev(){ 
var arr = $(':checkbox'); 
for(var i=0;i<arr.length;i++){ 
arr[i].checked = ! arr[i].checked; 
} 
}

//刷新数据
function shuaxin(){
	location.reload();
}
function countCheck(){
	console.log('...count');
	var count=0;
	//遍历复选框，对选中的进行计数
	var checkboxes = document.getElementsByName('checkid');
	for(var i=0;i<checkboxes.length;i++){
		var c = checkboxes[i];//当前遍历到的checkbox
		if(c.checked){
			count++;
		}
	}
	//把计数更新到按钮徽章上
	var span = document.getElementById('countSpan');
	span.innerHTML=count;
	
}
function tijiao(){
	var count=0;
	var checkboxes=document.getElementsByName('checkid');
	for(var i=0;i<checkboxes.length;i++){
		var c = checkboxes[i];//当前遍历到的checkbox
		if(c.checked){
			count++;
		}
	}
	if(count=0){
		alert('请先选择数据再提交');
	}
}




</script>


	</body>
</html>
    